package complex;

public class Complex {
    public double realPart, imaginaryPart;
    Complex(double x, double y) {
        realPart = x;
        imaginaryPart = y;
    }
    String print(){
        return String.format("%.3f+%.3fi", realPart, imaginaryPart);
    }
    void add(Complex new_complex) {
        realPart += new_complex.realPart;
        imaginaryPart += new_complex.imaginaryPart;
    }
    void sub(Complex new_complex) {
        realPart -= new_complex.realPart;
        imaginaryPart -= new_complex.imaginaryPart;
    }
    void multi(Complex new_complex) {
        double x = realPart * new_complex.realPart - imaginaryPart * new_complex.imaginaryPart;
        double y = realPart * new_complex.imaginaryPart + imaginaryPart * new_complex.realPart;
        realPart = x;
        imaginaryPart = y;
    }
    void div(Complex new_complex) {
        double x = imaginaryPart * new_complex.imaginaryPart + realPart * new_complex.realPart;
        double y = imaginaryPart * new_complex.realPart - realPart * new_complex.imaginaryPart;
        double z = new_complex.realPart * new_complex.realPart + new_complex.imaginaryPart * new_complex.imaginaryPart;
        realPart = x / z;
        imaginaryPart = y / z;
    }
}
